package com.netdisk.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;

@Component("jsonTest")
@Scope("prototype")
public class JsonTest extends ActionSupport{
	private String field1 = "str";
	private int[] ints = { 10, 20 };
	private Map map = new HashMap();
	private String customName = "custom";

	// 'transient' fields are not serialized
	private transient String field2;

	// fields without getter method are not serialized
	private String field3;

	public String execute() {
		map.put("John", "Galt");
		return SUCCESS;
	}

	public String getField1() {
		return field1;
	}

	public void setField1(String field1) {
		this.field1 = field1;
	}

	public int[] getInts() {
		return ints;
	}

	public void setInts(int[] ints) {
		this.ints = ints;
	}

	public Map getMap() {
		return map;
	}

	public void setMap(Map map) {
		this.map = map;
	}

	@JSON(name="newName")
	public String getCustomName() {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession	session =  request.getSession();
		return this.customName;
	}
}
